<?php

namespace app\common\controller;

use think\Controller;
use think\Request;
use app\common\cache\RedisPackage;

class Common extends Controller
{
    public $param;
    protected static $redis;
    public function _initialize()
    {
        parent::_initialize();

        /*防止跨域*/
        //header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
        header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, authKey, sessionId");
        $param = Request::instance()->param();
        $this->param = $param;

        //初始化构造redis单例
        self::$redis=RedisPackage::getInstance();
    }

    public function object_array($array)
    {
        if (is_object($array)) {
            $array = (array)$array;
        }
        if (is_array($array)) {
            foreach ($array as $key => $value) {
                $array[$key] = $this->object_array($value);
            }
        }
        return $array;
    }
}
